import request from '../../service/network.js'
Page({

  data: {
    show:false,
    title:'',
    address:'成都',
    facilities:[],
    screenArry: [
      { id: 0, name: '大床', select: false },
      { id: 1, name: '双床', select: false },
      { id: 2, name: '含早', select: false },
      { id: 3, name: '可取消', select: false },
    ],
    startmonth:9,
    startday:19,
    endmonth:9,
    endday:22,
    week:1,
    jitian:'2',
    id:0,
  },
  tanchuang(){
    this.setData({
      show:!this.data.show
    })
  },
  hidden(){
    this.setData({
      show:false
    })
  },
  //酒店信息跳转
  jiudianxinxi() {
    wx.navigateTo({
      url: '/pages/hotelinfo/hotelinfo',
    })
  },
  //跳转日历
  riqi(){
    wx.navigateTo({
      url: '/pages/calendar/calendar',
    })
  },
  //点击添加背景颜色
  addColor(e){
    
    let item=e.currentTarget.dataset.item;
    let isSelect=!item.select;
    let arr=this.data.screenArry;
    let newArry=[];
    arr.forEach(el => {
      if(el.id===item.id)
      {
        el.select=isSelect
      }
      newArry.push(el);
    });
    this.setData({
      screenArry:newArry
    })
  },
  //发送网络请求
  //1.酒店列表请求
  sendAjax() {
    //let that = this;
    return request({
      url: 'microHotelBook/queryDetailHotel',
      method: 'post',
      data: {
        id:this.data.id
      }
    })
  },
  //评价信息
  // 网络请求
  // evaluateAjax(){
  //   return request({
  //     url: 'microHotelBook/queryTotalEvaluation',
  //     data: {
  //       id: this.data.id
  //     }
  //   })
  // },
  // ---房间信息--
  roomdetails(){
    return request({
      url: '/microHotelBook/microHotelDetail',
      data: {
        "microHotel":{
          "id":this.data.id
        },
        "microRoomTypes":[{
          "id": this.data.id
        }]
      }
    })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    wx.setNavigationBarTitle({
      title: '酒店详情',
    })
      let id = options.id;
      this.setData({
        id:id
      })
    
    this.sendAjax().then(res => {
      let data=res.data.data;
      let title=data.name;
      let address=data.address;
      let facilities = data.facilities;
      
      let facilities1 = facilities.split(',');
      
      this.setData({
        title,
        address,
        facilities: facilities1
      })
    }).catch(err => {
      console.log(err);
    });
    //详情评价
    // this.evaluateAjax().then(res =>{
    //   console.log(res);
    // }).catch(err =>{
    //   console.log(err);

    // })
    //查询该酒店的房间
    this.roomdetails().then(res =>{
      console.log(res);
      
    }).catch(err =>{
      console.log(err);
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
      
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})